package com.zhida.smartcontrol.pagectrl.devicedetail.newdata;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.yanzhenjie.kalle.Params;
import com.zhida.smartcontrol.common.Api;
import com.zhida.smartcontrol.knet.KalleCallBack;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;

/**
 * author: tanjianpei
 * date: 2019/10/17 017 13:09
 * description:
 */
public class NewDataPresenter extends BasePresenterImpl<NewDataContract.View> implements NewDataContract.Presenter {

    @Override
    public void requestData(String code, String switchType) {
        if (TextUtils.isEmpty(code) || TextUtils.isEmpty(switchType)) {
            mView.showMsg("不正确的设备编码");
            return;
        }
        //deviceId设备 code, 如果是 ZigBee 单灯，需要传递的是其所属集控的 code
        Params params = Params.newBuilder()
                .add("deviceId", code)
                .add("switchType", switchType)
                .build();
        mKalleCenter.get(Api.GET_LATEST_DATA, params, true, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                NewDataBean bean = JSON.parseObject(result, NewDataBean.class);
                mView.showData(bean);
            }

            @Override
            public void onFailed(String msg) {
                mView.showMsg(msg);
            }
        });
    }
}
